package com.supply.dl.utils;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;

import com.supply.dl.bean.PhoneInfoBean;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 类描述：　[系统工具类]<br/>
 * 项目名称：[forumapp]<br/>
 * 包名：　　[com.hero.qmqzzs.utils]<br/>
 * 创建人：　[antao]<br/>
 * 创建时间：[2018/1/8 15:34]<br/>
 * 版本：　　[v2.1.0]<br/>
 */
public class SystemUtil
{
	/**
	 * 获取手机IMEI号
	 */
	@SuppressLint("MissingPermission")
	public static String getIMEI(Context context)
	{
		TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
		return telephonyManager.getDeviceId();
	}
	/*
     * 将时间戳转换为时间
     */
	public static String stampToDate(String s){
		String res;
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM/dd HH:mm");
		long lt = new Long(s);
		Date date = new Date(lt);
		res = simpleDateFormat.format(date);
		return res;
	}

	public static void showSoftInput(Activity activity, View view) {
		activity.getWindow().setSoftInputMode(
				WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
		InputMethodManager imm = (InputMethodManager) activity
				.getSystemService(Context.INPUT_METHOD_SERVICE);
		imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
	}

	/**
	 * 隐藏软键盘
	 *
	 * @param activity
	 * @param view
	 */
	public static void hideSoftInput(Activity activity, View view) {
		if (view != null) {
			InputMethodManager imm = (InputMethodManager) activity
					.getSystemService(Context.INPUT_METHOD_SERVICE);
			imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
		}
	}


	/**
	 * 获取当前手机的屏幕宽和高
	 * @param activity
	 * @return
	 */
	public static PhoneInfoBean getPhoneWidthAndHeight(Activity activity){
		PhoneInfoBean bean=new PhoneInfoBean();
		// 通过WindowManager获取屏幕宽度
		DisplayMetrics dm = new DisplayMetrics();
		activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
		bean.setDisWidth(dm.widthPixels);
		bean.setDisHeight(dm.heightPixels);
		return bean;
	}
}
